package winter_vacation_homework.day_14;

/**
 * 【LeetCode题号: 724. 寻找数组的中心下标】
 * https://leetcode-cn.com/problems/find-pivot-index/
 */
public class FindCenterIndexOfArray {
    public int pivotIndex(int[] nums) {
        int numLeft = 0;
        int numRight = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < i; j++) {
                numLeft += nums[j];
            }
            for (int j = i + 1; j < nums.length; j++) {
                numRight += nums[j];
            }

            if (numLeft == numRight) {
                return i;
            }
            numLeft = 0;
            numRight = 0;

        }
        return -1;
    }
}
